//
// Source code recreated from a .class file by IntelliJ IDEA
// (powered by Fernflower decompiler)
//

package com.robam.cloud.restful.config.swagger;

import com.robam.cloud.common.bean.common.Constant;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.context.annotation.Profile;
import springfox.documentation.builders.ApiInfoBuilder;
import springfox.documentation.builders.ParameterBuilder;
import springfox.documentation.builders.PathSelectors;
import springfox.documentation.builders.RequestHandlerSelectors;
import springfox.documentation.schema.ModelRef;
import springfox.documentation.service.ApiInfo;
import springfox.documentation.service.Parameter;
import springfox.documentation.spi.DocumentationType;
import springfox.documentation.spring.web.plugins.Docket;
import springfox.documentation.swagger2.annotations.EnableSwagger2;

import java.util.ArrayList;
import java.util.List;

@Configuration
@EnableSwagger2
@Slf4j
@Profile({"dev", "test"})
public class SwaggerConfig {
    @Value("${robam.component.restful.swagger.show}")
    private boolean swaggerShow;
    @Value("${robam.component.restful.swagger.host}")
    private String host;
    @Value("${robam.component.restful.swagger.path}")
    private String path;

    public SwaggerConfig() {
    }

    @Bean
    public Docket createRestApi() {
        log.debug("swagger初始化");
        ParameterBuilder tokenPar = new ParameterBuilder();
        List<Parameter> operationParameters = new ArrayList();
        tokenPar.name(Constant.TOKENNAME).description("令牌").modelRef(new ModelRef("string")).parameterType("header").required(false).build();
        operationParameters.add(tokenPar.build());
        return (new Docket(DocumentationType.SWAGGER_2)).enable(this.swaggerShow).host(host).pathMapping(path).apiInfo(this.apiInfo()).select().apis(RequestHandlerSelectors.basePackage("com.robam")).paths(PathSelectors.any()).build().globalOperationParameters(operationParameters);
    }

    private ApiInfo apiInfo() {
        return (new ApiInfoBuilder()).title("API文档").description("后台RestFul API").termsOfServiceUrl("admin@@robam.com").contact("robam").version("1.0").build();
    }


}
